// 用户类型定义
type User = {
  id: number
  name: string
  age?: number // 可选属性
  email: string
}

// 新增接口示例
interface Product {
  id: string
  name: string
  price: number
  inStock: boolean
  greet(): string // 方法定义
}

// 联合类型：表示状态
type Status = 'active' | 'inactive' | 'pending'

// 交叉类型：组合用户和管理员属性
type AdminUser = User & { isAdmin: boolean; permissions: string[] }

// 类型别名：函数类型
type Callback = (data: string) => void

export type { User, Status, AdminUser, Callback, Product }

// 类定义示例
class BaseClass {
  id: number
  name: string

  constructor(id: number, name: string) {
    this.id = id
    this.name = name
  }

  greet(): string {
    return `Hello, ${this.name}!`
  }
}

// 类继承示例
class DerivedClass extends BaseClass {
  age: number

  constructor(id: number, name: string, age: number) {
    super(id, name)
    this.age = age
  }

  greet(): string {
    return `${super.greet()} You are ${this.age} years old.`
  }
}

// 枚举：定义用户角色
enum UserRole {
  Guest = 'GUEST',
  Member = 'MEMBER',
  Admin = 'ADMIN',
}

export { BaseClass, DerivedClass, UserRole }
